home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / SLMaping.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  23.6 KB  |  852 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLMaping.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWMAPING_H
  13. #include "SLMaping.h"
  14. #endif
  15.  
  16. #ifndef PRGDEV_H
  17. #include "PRGDev.h"
  18. #endif
  19.  
  20. #ifndef SLREGION_H
  21. #include "SLRegion.h"
  22. #endif
  23.  
  24. #ifndef FWGRUTIL_H
  25. #include "FWGrUtil.h"
  26. #endif
  27.  
  28. #ifndef FWODGEOM_H
  29. #include "FWODGeom.h"
  30. #endif
  31.  
  32. #ifndef FWSOMENV_H
  33. #include "FWSOMEnv.h"
  34. #endif
  35.  
  36. // ----- OpenDoc Includes -----
  37.  
  38. #ifndef SOM_ODTransform_xh
  39. #include <Trnsform.xh>
  40. #endif
  41.  
  42. #ifndef SOM_ODShape_xh
  43. #include <Shape.xh>
  44. #endif
  45.  
  46. #ifdef FW_BUILD_MAC
  47. #pragma segment FW_Graphics
  48. #endif
  49.  
  50. //========================================================================================
  51. //    Local prototypes
  52. //========================================================================================
  53.  
  54. static void                ClearCache(FW_SMapping& mapping, Environment* ev);
  55.  
  56. static void                CheckCache(
  57.                             const FW_SMapping& mapping,
  58.                             Environment* ev,
  59.                             FW_HGDevice device,
  60.                             ODTransform* transform);
  61.  
  62. static void                CalcCache(
  63.                             FW_SMapping& mapping,
  64.                             Environment* ev,
  65.                             FW_HGDevice device,
  66.                             ODTransform* transform);
  67.  
  68. static void                CalcOriginOffset(
  69.                             FW_SMapping& mapping,
  70.                             Environment* ev,
  71.                             FW_HGDevice device);
  72.  
  73. //========================================================================================
  74. //    Mapping functions
  75. //========================================================================================
  76.  
  77. //----------------------------------------------------------------------------------------
  78. //    FW_PrivMapping_Init
  79. //----------------------------------------------------------------------------------------
  80.  
  81. void SL_API FW_PrivMapping_Init(FW_SMapping& mapping, FW_EMappingModes mappingMode)
  82. {
  83.     // No try block necessary - Do not throw
  84.     mapping.fMappingMode                =     mappingMode;
  85.     mapping.fRecentDevice                =    NULL;
  86.     mapping.fRecentODTransform            =    NULL;
  87.     mapping.fLogicalToContentTransform    =    NULL;
  88.     mapping.fContentToDeviceTransform    =    NULL;
  89.     mapping.fLogicalToDeviceTransform    =    NULL;
  90.     mapping.fHaveTransforms                =    FALSE;
  91.  
  92.     mapping.fDeviceOrg.x                 = 
  93.     mapping.fDeviceOrg.y                 = 
  94.     mapping.fLogicalOrg.x                 = 
  95.     mapping.fLogicalOrg.y                 =    FW_kFixed0;
  96.  
  97.     mapping.fLogicalExtent.x             =
  98.     mapping.fLogicalExtent.y             =
  99.     mapping.fDeviceExtent.x             =
  100.     mapping.fDeviceExtent.y             =    FW_kFixedPos1;
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. //    FW_PrivMapping_InitFromCopy
  105. //----------------------------------------------------------------------------------------
  106.  
  107. void SL_API FW_PrivMapping_InitFromCopy(FW_SMapping& mapping, const FW_SMapping& mapping2)
  108. {
  109.     // No try block necessary - Do not throw
  110.     mapping.fMappingMode                =     mapping2.fMappingMode;
  111.     mapping.fRecentDevice                =    NULL;
  112.     mapping.fRecentODTransform            =    NULL;
  113.     mapping.fLogicalToContentTransform    =    NULL;
  114.     mapping.fContentToDeviceTransform    =    NULL;
  115.     mapping.fLogicalToDeviceTransform    =    NULL;
  116.     mapping.fHaveTransforms                =    FALSE;
  117.  
  118.     mapping.fDeviceOrg                     =    mapping2.fDeviceOrg;
  119.     mapping.fLogicalOrg                 =     mapping2.fLogicalOrg;
  120.  
  121.     mapping.fLogicalExtent                 =    mapping2.fLogicalExtent;
  122.     mapping.fDeviceExtent                 =    mapping2.fDeviceExtent;
  123. }
  124.  
  125. //----------------------------------------------------------------------------------------
  126. //    FW_PrivMapping_Term
  127. //----------------------------------------------------------------------------------------
  128.  
  129. void SL_API FW_PrivMapping_Term(FW_SMapping& mapping, Environment* ev)
  130. {
  131.     // No try block necessary - Do not throw
  132.     ClearCache(mapping, ev);
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. //    FW_PrivMapping_Reset
  137. //----------------------------------------------------------------------------------------
  138.  
  139. void SL_API FW_PrivMapping_Reset(FW_SMapping& mapping, Environment* ev)
  140. {
  141.     // No try block necessary - Do not throw
  142.     ClearCache(mapping, ev);
  143.     
  144.     mapping.fMappingMode = FW_kPoint;
  145.  
  146.     mapping.fLogicalExtent.x =
  147.     mapping.fLogicalExtent.y =
  148.     mapping.fDeviceExtent.x =
  149.     mapping.fDeviceExtent.y = FW_kFixedPos1;
  150.  
  151.     mapping.fDeviceOrg = FW_kZeroPoint;
  152.     mapping.fLogicalOrg = FW_kZeroPoint;
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    FW_PrivMapping_SetMode
  157. //----------------------------------------------------------------------------------------
  158.  
  159. void SL_API FW_PrivMapping_SetMode(FW_SMapping& mapping, Environment* ev, FW_EMappingModes newMappingMode)
  160. {
  161.     // No try block necessary - Do not throw
  162.     mapping.fMappingMode = newMappingMode;
  163.     
  164.     if (mapping.fMappingMode == FW_kCustomConstrained)
  165.         FW_PrivMapping_SetExtents(mapping, ev, mapping.fLogicalExtent, mapping.fDeviceExtent);    // already calls ClearCache
  166.     else
  167.         ClearCache(mapping, ev);
  168. }
  169.  
  170. //----------------------------------------------------------------------------------------
  171. //    FW_PrivMapping_SetExtents
  172. //----------------------------------------------------------------------------------------
  173.  
  174. void SL_API FW_PrivMapping_SetExtents(
  175.                                 FW_SMapping& mapping,
  176.                                 Environment* ev,
  177.                                 const FW_SPoint& logicalExtent,
  178.                                 const FW_SPoint& deviceExtent)
  179. {
  180.     // No try block necessary - Do not throw
  181.     mapping.fLogicalExtent = logicalExtent;
  182.     mapping.fDeviceExtent = deviceExtent;
  183.  
  184.     if (mapping.fMappingMode == FW_kCustomConstrained)
  185.     {
  186.         if (mapping.fDeviceExtent.x < mapping.fDeviceExtent.y)
  187.             mapping.fDeviceExtent.y = mapping.fDeviceExtent.x;
  188.         else
  189.             mapping.fDeviceExtent.x = mapping.fDeviceExtent.y;
  190.     }
  191.     
  192.     ClearCache(mapping, ev);
  193. }
  194.  
  195. //----------------------------------------------------------------------------------------
  196. //    FW_PrivMapping_SetDeviceOrigin
  197. //----------------------------------------------------------------------------------------
  198.  
  199. void SL_API FW_PrivMapping_SetDeviceOrigin(FW_SMapping& mapping, Environment* ev, FW_Fixed x, FW_Fixed y)
  200. {
  201.     // No try block necessary - Do not throw
  202.     mapping.fDeviceOrg.x = x;
  203.     mapping.fDeviceOrg.y = y;
  204.     ClearCache(mapping, ev);
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. //    FW_PrivMapping_SetLogicalOrigin
  209. //----------------------------------------------------------------------------------------
  210.  
  211. void SL_API FW_PrivMapping_SetLogicalOrigin(FW_SMapping& mapping, Environment* ev, FW_Fixed x, FW_Fixed y)
  212. {
  213.     // No try block necessary - Do not throw
  214.     mapping.fLogicalOrg.x = x;
  215.     mapping.fLogicalOrg.y = y;
  216.     ClearCache(mapping, ev);
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. //    FW_PrivMapping_GetOriginOffset
  221. //----------------------------------------------------------------------------------------
  222.  
  223. void SL_API FW_PrivMapping_GetOriginOffset(
  224.                                 const FW_SMapping& mapping,
  225.                                 Environment* ev,
  226.                                 FW_SPlatformPoint& offset,
  227.                                 FW_HGDevice device,
  228.                                 ODTransform* transform)
  229. {
  230.     // No try block necessary - Do not throw
  231.     CheckCache(mapping, ev, device, transform);
  232.     offset = mapping.fOriginOffset;
  233. }
  234.  
  235. //========================================================================================
  236. //    Local helpers
  237. //========================================================================================
  238.  
  239. //----------------------------------------------------------------------------------------
  240. //    ClearCache
  241. //----------------------------------------------------------------------------------------
  242.  
  243. static void ClearCache(FW_SMapping& mapping, Environment* ev)
  244. {
  245.     // Will not throw
  246.     FW_SOM_TRY
  247.     {
  248.         if (mapping.fRecentDevice != NULL)
  249.         {
  250.             mapping.fRecentDevice->Release();
  251.             mapping.fRecentDevice = NULL;
  252.         }
  253.     
  254.         if (mapping.fRecentODTransform != NULL)
  255.         {
  256.             mapping.fRecentODTransform->Release(ev);
  257.             mapping.fRecentODTransform = NULL;
  258.         }
  259.     
  260.         if (mapping.fLogicalToContentTransform != NULL)
  261.         {
  262.             mapping.fLogicalToContentTransform->Release(ev);
  263.             mapping.fLogicalToContentTransform = NULL;
  264.         }
  265.     
  266.         if (mapping.fContentToDeviceTransform != NULL)
  267.         {
  268.             mapping.fContentToDeviceTransform->Release(ev);
  269.             mapping.fContentToDeviceTransform = NULL;
  270.         }
  271.     
  272.         if (mapping.fLogicalToDeviceTransform != NULL)
  273.         {
  274.             mapping.fLogicalToDeviceTransform->Release(ev);
  275.             mapping.fLogicalToDeviceTransform = NULL;
  276.         }
  277.         
  278.         mapping.fHaveTransforms = FALSE;
  279.     }
  280.     FW_SOM_CATCH
  281. }
  282.  
  283. //----------------------------------------------------------------------------------------
  284. //    CheckCache
  285. //----------------------------------------------------------------------------------------
  286.  
  287. static void CheckCache(const FW_SMapping& mapping,
  288.                         Environment* ev,
  289.                         FW_HGDevice device,
  290.                         ODTransform* transform)
  291. {
  292.     // No try block necessary - Do not throw
  293.     if (!mapping.fHaveTransforms || device != mapping.fRecentDevice || transform != mapping.fRecentODTransform)
  294.         CalcCache((FW_SMapping&)mapping, ev, device, transform);
  295.  
  296.     FW_ASSERT(mapping.fHaveTransforms);
  297.     FW_ASSERT(mapping.fLogicalToContentTransform != NULL);
  298.     FW_ASSERT(mapping.fContentToDeviceTransform != NULL);
  299.     FW_ASSERT(mapping.fLogicalToDeviceTransform != NULL);
  300. }
  301.  
  302. //----------------------------------------------------------------------------------------
  303. //    CalcCache
  304. //----------------------------------------------------------------------------------------
  305.  
  306. static void CalcCache(FW_SMapping& mapping,
  307.                     Environment* ev,
  308.                     FW_HGDevice device,
  309.                     ODTransform* transform)
  310. {
  311. // #define LOG_TRANSFORMS
  312.  
  313.     FW_SOM_TRY
  314.     {
  315.         ClearCache(mapping, ev);
  316.     
  317.         mapping.fRecentDevice = device;
  318.         if(mapping.fRecentDevice != NULL)
  319.         {
  320.             mapping.fRecentDevice->Acquire();
  321.         }
  322.             
  323.         mapping.fRecentODTransform = transform;
  324.         if(mapping.fRecentODTransform != NULL) 
  325.         {
  326.     #ifdef FW_BUILD_WIN
  327.             mapping.fRecentODTransform->IncrementRefCount(ev);
  328.     #endif
  329.     #ifdef FW_BUILD_MAC
  330.             mapping.fRecentODTransform->Acquire(ev);
  331.     #endif
  332.         }
  333.     
  334.         ODCanvas* canvas = device != NULL ? device->GetODCanvas() : NULL;
  335.         
  336.         FW_CPoint resScreen;
  337.     
  338.     #ifdef FW_BUILD_WIN
  339.         HDC hDC = ::GetDC(NULL);
  340.     
  341.         resScreen.x    = FW_IntToFixed(::GetDeviceCaps(hDC, LOGPIXELSX));
  342.         resScreen.y    = FW_IntToFixed(::GetDeviceCaps(hDC, LOGPIXELSY));
  343.     
  344.         ::ReleaseDC(NULL, hDC);
  345.         
  346.         BOOL bWinIsPrinting = canvas != NULL ? canvas->HasPlatformPrintJob(ev, kODWindows) : FALSE;
  347.     #endif
  348.     #ifdef FW_BUILD_MAC
  349.         resScreen.Set(FW_kFixed72, FW_kFixed72);
  350.     #endif
  351.     
  352.         FW_CPoint resDevice = device == NULL ? resScreen : device->GetResolution();
  353.             
  354.         FW_CPoint ptLogicalToContentOffset(-mapping.fLogicalOrg.x, -mapping.fLogicalOrg.y);
  355.         FW_CPoint ptLogicalToContentScaling;
  356.         FW_CPoint resScale;
  357.     
  358.         switch (mapping.fMappingMode)
  359.         {
  360.             case FW_kCentimeter:
  361.                 ptLogicalToContentScaling.x = FW_DoubleToFixed(28.346456691);
  362.                 ptLogicalToContentScaling.y = FW_DoubleToFixed(28.346456691);
  363.                 break;
  364.     
  365.             case FW_kInch:
  366.                 ptLogicalToContentScaling.x = FW_kFixed72;
  367.                 ptLogicalToContentScaling.y = FW_kFixed72;
  368.                 break;
  369.     
  370.             case FW_kPoint:    
  371.                 //    On the Mac:
  372.                 //        The screen is always assumed to be 72dpi, even though actual
  373.                 //        resolution may vary (this is the tradition!)
  374.                 //    On Windows:
  375.                 //        OpenDoc/Win emulates 72dpi
  376.                 ptLogicalToContentScaling.x = FW_kFixedPos1;
  377.                 ptLogicalToContentScaling.y = FW_kFixedPos1;
  378.                 break;
  379.     
  380.             case FW_kDevice:
  381.     #ifdef FW_BUILD_MAC
  382.                 ptLogicalToContentScaling.x = FW_kFixedPos1;
  383.                 ptLogicalToContentScaling.y = FW_kFixedPos1;
  384.     #endif
  385.     #ifdef FW_BUILD_WIN
  386.                 if (bWinIsPrinting)
  387.                 {
  388.                     // For printing, preserve the visual image size
  389.                     ptLogicalToContentScaling.x = FW_kFixed72 / resScreen.x;
  390.                     ptLogicalToContentScaling.y = FW_kFixed72 / resScreen.y;
  391.                 }
  392.                 else
  393.                 {
  394.                     // Counter-act OpenDoc's 72 dpi emulation
  395.                     ptLogicalToContentScaling.x = FW_kFixed72 / resDevice.x;
  396.                     ptLogicalToContentScaling.y = FW_kFixed72 / resDevice.y;
  397.                 }
  398.     #endif
  399.                 break;
  400.     
  401.             case FW_kCustomConstrained:
  402.             case FW_kCustomUnconstrained:
  403.                 resScale.x = FW_kFixed72 / resDevice.x;
  404.                 resScale.y = FW_kFixed72 / resDevice.y;
  405.     
  406.                 ptLogicalToContentScaling.x =
  407.                     FW_WideMultiply(resScale.x, mapping.fDeviceExtent.x) / mapping.fLogicalExtent.x;
  408.                     
  409.                 ptLogicalToContentScaling.y =
  410.                     FW_WideMultiply(resScale.y, mapping.fDeviceExtent.y) / mapping.fLogicalExtent.y;
  411.     
  412.                 ptLogicalToContentOffset.x  = 
  413.                     FW_WideMultiply(mapping.fDeviceOrg.x, FW_kFixed72) / resDevice.x - mapping.fLogicalOrg.x * ptLogicalToContentScaling.x;
  414.     
  415.                 ptLogicalToContentOffset.y  =
  416.                     FW_WideMultiply(mapping.fDeviceOrg.y, FW_kFixed72) / resDevice.y - mapping.fLogicalOrg.y * ptLogicalToContentScaling.y;
  417.     
  418.                 break;
  419.         }
  420.     
  421.         // ----- Logical to content transform
  422.         mapping.fLogicalToContentTransform = ::FW_NewODTransform(ev, ptLogicalToContentOffset, ptLogicalToContentScaling);
  423.     
  424.         // ----- Content to device transform
  425.         if(transform != NULL)
  426.         {
  427.     #ifdef LOG_TRANSFORMS
  428.             FW_LogTransform(ev, "OD Content        ", transform);
  429.     #endif
  430.             mapping.fContentToDeviceTransform = ::FW_NewODTransform(ev, transform);
  431.         }
  432.         else
  433.         {
  434.             FW_CPoint scaling;
  435.     #ifdef FW_BUILD_WIN
  436.             if (bWinIsPrinting && mapping.fMappingMode == FW_kDevice)
  437.             {
  438.                 // Preserve visual image size
  439.                 scaling.x = resScreen.x / FW_kFixed72;
  440.                 scaling.y = resScreen.y / FW_kFixed72;
  441.             }
  442.             else
  443.     #endif
  444.             {
  445.                 scaling.x = resDevice.x / FW_kFixed72;
  446.                 scaling.y = resDevice.y / FW_kFixed72;
  447.             }
  448.     
  449.             mapping.fContentToDeviceTransform = ::FW_NewODTransform(ev);
  450.             mapping.fContentToDeviceTransform->ScaleBy(ev, (ODPoint*) &scaling);        
  451.         }
  452.     
  453.         // ------ Logical to device transform -----
  454.         mapping.fLogicalToDeviceTransform = ::FW_NewODTransform(ev, mapping.fLogicalToContentTransform);
  455.         mapping.fLogicalToDeviceTransform->PostCompose(ev, mapping.fContentToDeviceTransform);
  456.     
  457.         // ----- Adjust the origin
  458.         CalcOriginOffset(mapping, ev, device);
  459.     
  460.     #ifdef LOG_TRANSFORMS
  461.         FW_LogTransform(ev, "Logical -> Content", mapping.fLogicalToContentTransform);
  462.         FW_LogTransform(ev, "Content -> Device ", mapping.fContentToDeviceTransform);
  463.         FW_LogTransform(ev, "Logical -> Device ", mapping.fLogicalToDeviceTransform);
  464.     #endif
  465.     
  466.         mapping.fHaveTransforms = TRUE;
  467.     }
  468.     FW_SOM_CATCH
  469. }
  470.  
  471. //----------------------------------------------------------------------------------------
  472. //    CalcOriginOffset
  473. //----------------------------------------------------------------------------------------
  474.  
  475. static void CalcOriginOffset(FW_SMapping& mapping,
  476.                             Environment* ev,
  477.                             FW_HGDevice device)
  478. {
  479.     FW_SOM_TRY
  480.     {
  481.         ODCanvas* canvas = device != NULL ? device->GetODCanvas() : NULL;
  482.         FW_Boolean isPrinting = canvas != NULL && 
  483.     #ifdef FW_BUILD_WIN
  484.             (canvas->HasPlatformPrintJob(ev, kODWindows));
  485.     #endif
  486.     #ifdef FW_BUILD_MAC
  487.             (canvas->HasPlatformPrintJob(ev, kODQuickDrawGX) || canvas->HasPlatformPrintJob(ev, kODQuickDraw));
  488.     #endif
  489.     
  490.         FW_CPoint offset;
  491.         mapping.fLogicalToDeviceTransform->GetOffset(ev, offset);
  492.         if ((offset.x != FW_kFixed0 || offset.y != FW_kFixed0) && !isPrinting)
  493.         {
  494.             FW_SetXY(mapping.fOriginOffset, FW_FixedToInt(offset.x) % 8, FW_FixedToInt(offset.y) % 8);
  495.             offset.x = FW_IntToFixed(-FW_PointX(mapping.fOriginOffset));
  496.             offset.y = FW_IntToFixed(-FW_PointY(mapping.fOriginOffset));
  497.             mapping.fLogicalToDeviceTransform->MoveBy(ev, offset);
  498.         }
  499.         else
  500.         {
  501.             FW_SetXY(mapping.fOriginOffset, 0, 0);
  502.         }
  503.     }
  504.     FW_SOM_CATCH
  505. }
  506.  
  507. //----------------------------------------------------------------------------------------
  508. // ----- Logical ---> Content
  509. //----------------------------------------------------------------------------------------
  510.  
  511. void SL_API FW_PrivMapping_LogicalToContentPoint(
  512.                                 const FW_SMapping& mapping,
  513.                                 Environment* ev,
  514.                                 const FW_SPoint& ptFrom,
  515.                                 FW_SPoint& ptTo,
  516.                                 FW_HGDevice device,
  517.                                 ODTransform* transform)
  518. {
  519.     FW_SOM_TRY
  520.     {
  521.         CheckCache(mapping, ev, device, transform);
  522.         ptTo = FW_TransformCopy(ev, ptFrom, mapping.fLogicalToContentTransform);
  523.     }
  524.     FW_SOM_CATCH
  525. }
  526.  
  527. void SL_API FW_PrivMapping_LogicalToContentRect(
  528.                                 const FW_SMapping& mapping,
  529.                                 Environment* ev,
  530.                                 const FW_SRect& rectFrom,
  531.                                 FW_SRect& rectTo,
  532.                                 FW_HGDevice device,
  533.                                 ODTransform* transform)
  534. {
  535.     FW_SOM_TRY
  536.     {
  537.         CheckCache(mapping, ev, device, transform);
  538.         rectTo = FW_TransformCopy(ev, rectFrom, mapping.fLogicalToContentTransform);
  539.     }
  540.     FW_SOM_CATCH
  541. }
  542.  
  543. ODShape* SL_API FW_PrivMapping_LogicalToContentShape(
  544.                                 const FW_SMapping& mapping,
  545.                                 Environment* ev,
  546.                                 ODShape* shape,
  547.                                 FW_HGDevice device,
  548.                                 ODTransform* transform)
  549. {
  550.     ODShape* newShape = 0;
  551.  
  552.     FW_SOM_TRY
  553.     {
  554.         CheckCache(mapping, ev, device, transform);
  555.         newShape = shape->Copy(ev);
  556.         mapping.fLogicalToContentTransform->TransformShape(ev, newShape);
  557.     }
  558.     FW_SOM_CATCH
  559.  
  560.     return newShape;
  561. }
  562.  
  563. //----------------------------------------------------------------------------------------
  564. // ----- Logical ---> Device
  565. //----------------------------------------------------------------------------------------
  566.  
  567. void SL_API FW_PrivMapping_LogicalToDevicePoint(
  568.                                 const FW_SMapping& mapping,
  569.                                 Environment* ev,
  570.                                 const FW_SPoint& ptFrom,
  571.                                 FW_SPlatformPoint& ptTo,
  572.                                 FW_HGDevice device,
  573.                                 ODTransform* transform)
  574. {
  575.     FW_SOM_TRY
  576.     {
  577.         CheckCache(mapping, ev, device, transform);
  578.         FW_CPoint pt = FW_TransformCopy(ev, ptFrom, mapping.fLogicalToDeviceTransform);
  579.         ptTo = pt.AsPlatformPoint();
  580.     }
  581.     FW_SOM_CATCH
  582. }
  583.  
  584. void SL_API FW_PrivMapping_LogicalToDeviceRect(
  585.                                 const FW_SMapping& mapping,
  586.                                 Environment* ev,
  587.                                 const FW_SRect& rectFrom,
  588.                                 FW_SPlatformRect& rectTo,
  589.                                 FW_HGDevice device,
  590.                                 ODTransform* transform)
  591. {
  592.     FW_SOM_TRY
  593.     {
  594.         CheckCache(mapping, ev, device, transform);
  595.         FW_CRect rect = FW_TransformCopy(ev, rectFrom, mapping.fLogicalToDeviceTransform);
  596.         rectTo = rect.AsPlatformRect();
  597.     }
  598.     FW_SOM_CATCH
  599. }
  600.  
  601. ODShape* SL_API FW_PrivMapping_LogicalToDeviceShape(
  602.                                 const FW_SMapping& mapping,
  603.                                 Environment* ev,
  604.                                 ODShape* shape,
  605.                                 FW_HGDevice device,
  606.                                 ODTransform* transform)
  607. {
  608.     ODShape* newShape = 0;
  609.  
  610.     FW_SOM_TRY
  611.     {
  612.         CheckCache(mapping, ev, device, transform);
  613.         newShape = shape->Copy(ev);
  614.         mapping.fLogicalToDeviceTransform->TransformShape(ev, newShape);
  615.     }
  616.     FW_SOM_CATCH
  617.  
  618.     return newShape;
  619. }
  620.  
  621. //----------------------------------------------------------------------------------------
  622. // ----- Device ---> Logical
  623. //----------------------------------------------------------------------------------------
  624.  
  625. void SL_API FW_PrivMapping_DeviceToLogicalPoint(
  626.                                 const FW_SMapping& mapping,
  627.                                 Environment* ev,
  628.                                 const FW_SPlatformPoint& ptFrom,
  629.                                 FW_SPoint& ptTo,
  630.                                 FW_HGDevice device,
  631.                                 ODTransform* transform)
  632. {
  633.     FW_SOM_TRY
  634.     {
  635.         CheckCache(mapping, ev, device, transform);
  636.         FW_CPoint pt = ptFrom;
  637.         ptTo = FW_InverseTransformCopy(ev, pt, mapping.fLogicalToDeviceTransform);
  638.     }
  639.     FW_SOM_CATCH
  640. }
  641.  
  642. void SL_API FW_PrivMapping_DeviceToLogicalRect(
  643.                                 const FW_SMapping& mapping,
  644.                                 Environment* ev,
  645.                                 const FW_SPlatformRect& rectFrom,
  646.                                 FW_SRect& rectTo,
  647.                                 FW_HGDevice device,
  648.                                 ODTransform* transform)
  649. {
  650.     FW_SOM_TRY
  651.     {
  652.         CheckCache(mapping, ev, device, transform);
  653.         FW_CRect rect = rectFrom;
  654.         rectTo = rect.InverseTransformCopy(ev, mapping.fLogicalToDeviceTransform);
  655.     }
  656.     FW_SOM_CATCH
  657. }
  658.     
  659. ODShape* SL_API FW_PrivMapping_DeviceToLogicalShape(
  660.                                 const FW_SMapping& mapping,
  661.                                 Environment* ev,
  662.                                 ODShape* shape,
  663.                                 FW_HGDevice device,
  664.                                 ODTransform* transform)
  665. {
  666.     ODShape* newShape = 0;
  667.  
  668.     FW_SOM_TRY
  669.     {
  670.         CheckCache(mapping, ev, device, transform);
  671.         newShape = shape->Copy(ev);
  672.         mapping.fLogicalToDeviceTransform->InvertShape(ev, newShape);
  673.     }
  674.     FW_SOM_CATCH
  675.  
  676.     return newShape;
  677. }
  678.  
  679. //----------------------------------------------------------------------------------------
  680. // ----- Device ---> Content
  681. //----------------------------------------------------------------------------------------
  682.  
  683. void SL_API FW_PrivMapping_DeviceToContentPoint(
  684.                                 const FW_SMapping& mapping,
  685.                                 Environment* ev,
  686.                                 const FW_SPlatformPoint& ptFrom,
  687.                                 FW_SPoint& ptTo,
  688.                                 FW_HGDevice device,
  689.                                 ODTransform* transform)
  690. {
  691.     FW_SOM_TRY
  692.     {
  693.         CheckCache(mapping, ev, device, transform);
  694.         FW_CPoint pt = ptFrom;
  695.         ptTo = FW_InverseTransformCopy(ev, pt, mapping.fContentToDeviceTransform);
  696.     }
  697.     FW_SOM_CATCH
  698. }
  699.  
  700. void SL_API FW_PrivMapping_DeviceToContentRect(
  701.                                 const FW_SMapping& mapping,
  702.                                 Environment* ev,
  703.                                 const FW_SPlatformRect& rectFrom,
  704.                                 FW_SRect& rectTo,
  705.                                 FW_HGDevice device,
  706.                                 ODTransform* transform)
  707. {
  708.     FW_SOM_TRY
  709.     {
  710.         CheckCache(mapping, ev, device, transform);
  711.         FW_CRect rect = rectFrom;
  712.         rectTo = rect.InverseTransformCopy(ev, mapping.fContentToDeviceTransform);
  713.     }
  714.     FW_SOM_CATCH
  715. }
  716.  
  717. ODShape* SL_API FW_PrivMapping_DeviceToContentShape(
  718.                                 const FW_SMapping& mapping,
  719.                                 Environment* ev,
  720.                                 ODShape* shape,
  721.                                 FW_HGDevice device,
  722.                                 ODTransform* transform)
  723. {
  724.     ODShape* newShape = 0;
  725.  
  726.     FW_SOM_TRY
  727.     {
  728.         CheckCache(mapping, ev, device, transform);
  729.         newShape = shape->Copy(ev);
  730.         mapping.fContentToDeviceTransform->InvertShape(ev, newShape);
  731.     }
  732.     FW_SOM_CATCH
  733.  
  734.     return newShape;
  735. }
  736.  
  737. //----------------------------------------------------------------------------------------
  738. // ----- Content ---> Logical
  739. //----------------------------------------------------------------------------------------
  740.                             
  741. void SL_API FW_PrivMapping_ContentToLogicalPoint(
  742.                                 const FW_SMapping& mapping,
  743.                                 Environment* ev,
  744.                                 const FW_SPoint& ptFrom,
  745.                                 FW_SPoint& ptTo,
  746.                                 FW_HGDevice device,
  747.                                 ODTransform* transform)
  748. {
  749.     FW_SOM_TRY
  750.     {
  751.         CheckCache(mapping, ev, device, transform);
  752.         ptTo = FW_InverseTransformCopy(ev, ptFrom, mapping.fLogicalToContentTransform);
  753.     }
  754.     FW_SOM_CATCH
  755. }
  756.     
  757. void SL_API FW_PrivMapping_ContentToLogicalRect(
  758.                                 const FW_SMapping& mapping,
  759.                                 Environment* ev,
  760.                                 const FW_SRect& rectFrom,
  761.                                 FW_SRect& rectTo,
  762.                                 FW_HGDevice device,
  763.                                 ODTransform* transform)
  764. {
  765.     FW_SOM_TRY
  766.     {
  767.         CheckCache(mapping, ev, device, transform);
  768.         rectTo = FW_InverseTransformCopy(ev, rectFrom, mapping.fLogicalToContentTransform);
  769.     }
  770.     FW_SOM_CATCH
  771. }
  772.                                 
  773.     
  774. ODShape* SL_API FW_PrivMapping_ContentToLogicalShape(
  775.                                 const FW_SMapping& mapping,
  776.                                 Environment* ev,
  777.                                 ODShape* shape,
  778.                                 FW_HGDevice device,
  779.                                 ODTransform* transform)
  780. {
  781.     ODShape* newShape = 0;
  782.  
  783.     FW_SOM_TRY
  784.     {
  785.         CheckCache(mapping, ev, device, transform);
  786.         newShape = shape->Copy(ev);
  787.         mapping.fLogicalToContentTransform->InvertShape(ev, newShape);
  788.     }
  789.     FW_SOM_CATCH
  790.  
  791.     return newShape;
  792. }
  793.  
  794. //----------------------------------------------------------------------------------------
  795. // ----- Content ---> Device
  796. //----------------------------------------------------------------------------------------
  797.  
  798. void SL_API FW_PrivMapping_ContentToDevicePoint(
  799.                                 const FW_SMapping& mapping,
  800.                                 Environment* ev,
  801.                                 const FW_SPoint& ptFrom,
  802.                                 FW_SPlatformPoint& ptTo,
  803.                                 FW_HGDevice device,
  804.                                 ODTransform* transform)
  805. {
  806.     FW_SOM_TRY
  807.     {
  808.         CheckCache(mapping, ev, device, transform);
  809.         FW_CPoint pt = FW_TransformCopy(ev, ptFrom, mapping.fContentToDeviceTransform);
  810.         ptTo = pt.AsPlatformPoint();
  811.     }
  812.     FW_SOM_CATCH
  813. }
  814.  
  815. void SL_API FW_PrivMapping_ContentToDeviceRect(
  816.                                 const FW_SMapping& mapping,
  817.                                 Environment* ev,
  818.                                 const FW_SRect& rectFrom,
  819.                                 FW_SPlatformRect& rectTo,
  820.                                 FW_HGDevice device,
  821.                                 ODTransform* transform)
  822. {
  823.     FW_SOM_TRY
  824.     {
  825.         CheckCache(mapping, ev, device, transform);
  826.         FW_CRect rect = FW_TransformCopy(ev, rectFrom, mapping.fContentToDeviceTransform);
  827.         rectTo = rect.AsPlatformRect();
  828.     }
  829.     FW_SOM_CATCH
  830. }
  831.  
  832. ODShape* SL_API FW_PrivMapping_ContentToDeviceShape(
  833.                                 const FW_SMapping& mapping,
  834.                                 Environment* ev,
  835.                                 ODShape* shape,
  836.                                 FW_HGDevice device,
  837.                                 ODTransform* transform)
  838. {
  839.     ODShape* newShape = 0;
  840.  
  841.     FW_SOM_TRY
  842.     {
  843.         CheckCache(mapping, ev, device, transform);
  844.         newShape = shape->Copy(ev);
  845.         mapping.fContentToDeviceTransform->TransformShape(ev, newShape);
  846.     }
  847.     FW_SOM_CATCH
  848.  
  849.     return newShape;
  850. }
  851.  
  852.